/*
 *	OpenSource code or fragments by avocado systems, Marcus Fuhrmeister
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions
 *	are met:
 *  
 *		* Redistribution of source code must retain the above OpenSource comment,
 *		this list of conditions and the following disclaimer.
 * 
 *		* Redistribution in binary form must reproduce the above OpenSource comment,
 *		this list of conditions and the following disclaimer in the
 *		documentation and/or other materials provided with the distribution.
 * 
 *	Neither the name of 'avocaod systems, Marcus Fuhrmeister' or the
 *	names of contributors may be used to endorse or promote products derived
 *	from this software without specific prior written permission.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 */
package de.fuhrmeister.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;

import de.fuhrmeister.browserchooser.controller.Controller;

/**
 * Configuration manager handling pre-configuration variables, strings and preferences.
 * 
 * @date	24.08.2010
 * @author	Marcus Fuhrmeister
 */
public class ConfigManager {

	private static ConfigManager configMng;
	private Properties configBundle;
	private final Properties strings;
	private Properties preferences;
	private ArrayList<String> languages;

	private static final String CONFIG_FILE_BASENAME = "config.properties";

	// configurations
	private static final String CONFIG_FILE = "CONFIG_FILE";
	private static final String PREFERENCES_FOLDER = "PREFERENCES_FOLDER";
	private static final String PREFERENCES_FILE = "PREFERENCES_FILE";
	public static final String MODEL_FOLDER = "MODEL_FOLDER";
	public static final String MODEL_FILE = "MODEL_FILE";
	public static final String STRINGS_FOLDER = "STRINGS_FOLDER";
	public static final String STRINGS_FILEEXT = "STRINGS_FILEEXT";
	public static final String LANGUAGE_DEFAULT = "LANGUAGE_DEFAULT";

	public static final String DOCKLET_LOCATION_TOP = "DOCKLET_LOCATION_TOP";
	public static final String DOCKLET_LOCATION_RIGHT = "DOCKLET_LOCATION_RIGHT";
	public static final String DOCKLET_LOCATION_BOTTOM = "DOCKLET_LOCATION_BOTTOM";
	public static final String DOCKLET_LOCATION_LEFT = "DOCKLET_LOCATION_LEFT";
	public static final String DOCKLET_ICON_SIZE_MAX = "DOCKLET_ICON_SIZE_MAX";
	public static final String DOCKLET_ICON_SIZE_MIN = "DOCKLET_ICON_SIZE_MIN";
	public static final String DOCKLET_ICON_SIZE_EXTENT = "DOCKLET_ICON_SIZE_EXTENT";
	public static final String DOCKLET_ICON_SPACE = "DOCKLET_ICON_SPACE";
	public static final String DOCKLET_BACKGROUND = "DOCKLET_BACKGROUND";

	public static final String SETTINGS_SIZE_WIDTH = "SETTINGS_SIZE_WIDTH";
	public static final String SETTINGS_SIZE_HEIGHT = "SETTINGS_SIZE_HEIGHT";
	public static final String SETTINGS_BUTTONPANEL_SIZE_WIDTH = "SETTINGS_BUTTONPANEL_SIZE_WIDTH";
	public static final String SETTINGS_BUTTONPANEL_SIZE_HEIGHT = "SETTINGS_BUTTONPANEL_SIZE_HEIGHT";
	public static final String SETTINGS_BUTTON_SAVE_COORDINATE_X = "SETTINGS_BUTTON_SAVE_COORDINATE_X";
	public static final String SETTINGS_BUTTON_SAVE_COORDINATE_Y = "SETTINGS_BUTTON_SAVE_COORDINATE_Y";
	public static final String SETTINGS_BUTTON_SAVE_SIZE_WIDTH = "SETTINGS_BUTTON_SAVE_SIZE_WIDTH";
	public static final String SETTINGS_BUTTON_SAVE_SIZE_HEIGHT = "SETTINGS_BUTTON_SAVE_SIZE_HEIGHT";
	public static final String SETTINGS_BUTTON_ABORT_COORDINATE_X = "SETTINGS_BUTTON_ABORT_COORDINATE_X";
	public static final String SETTINGS_BUTTON_ABORT_COORDINATE_Y = "SETTINGS_BUTTON_ABORT_COORDINATE_Y";
	public static final String SETTINGS_BUTTON_ABORT_SIZE_WIDTH = "SETTINGS_BUTTON_ABORT_SIZE_WIDTH";
	public static final String SETTINGS_BUTTON_ABORT_SIZE_HEIGHT = "SETTINGS_BUTTON_ABORT_SIZE_HEIGHT";

	// preferences
	public static final String DOCKLET_SIZE_WIDTH = "DOCKLET_SIZE_WIDTH";
	public static final String DOCKLET_SIZE_HEIGHT = "DOCKLET_SIZE_HEIGHT";
	public static final String DOCKLET_ALWAYSONTOP = "DOCKLET_ALWAYSONTOP";
	public static final String DOCKLET_LOCATION = "DOCKLET_LOCATION";
	public static final String DOCKLET_ICON_SIZE = "DOCKLET_ICON_SIZE";
	public static final String LANGUAGE = "LANGUAGE";
	public static final String ANIMATION_SPEED = "ANIMATION_SPEED";
	public static final String ANIMATION_DELAY = "ANIMATION_DELAY";

	// strings
	public static final String STRING_STANDARDS_YES = "STRING_STANDARDS_YES";
	public static final String STRING_STANDARDS_NO = "STRING_STANDARDS_NO";

	public static final String STRING_TOOLTIP_MENUITEM_SHORTCUT = "STRING_TOOLTIP_MENUITEM_SHORTCUT";
	public static final String STRING_MENUITEM_NEW = "MENUITEM_NEW";
	public static final String STRING_MENUITEM_SETTINGS = "MENUITEM_SETTINGS";
	public static final String STRING_MENUITEM_LANGUAGE = "MENUITEM_LANGUAGE";
	public static final String STRING_MENUITEM_LANGUAGELOAD = "MENUITEM_LANGUAGELOAD";
	public static final String STRING_MENUITEM_EXIT = "MENUITEM_EXIT";
	public static final String STRING_MENUITEM_LANGUAGE_NAME = "MENUITEM_LANGUAGE_NAME";
	public static final String STRING_FILEEXT_DESC = "STRING_FILEEXT_DESC";

	public static final String STRING_LABEL_OPTIONS = "STRING_LABEL_OPTIONS";
	public static final String STRING_TAB_LABEL_NEW = "STRING_TAB_LABEL_NEW";
	public static final String STRING_BUTTON_SAVE = "STRING_BUTTON_SAVE";
	public static final String STRING_BUTTON_ABORT = "STRING_BUTTON_ABORT";
	public static final String STRING_LABEL_ICONSIZE = "STRING_LABEL_ICONSIZE";
	public static final String STRING_LABEL_ALWAYSONTOP = "STRING_LABEL_ALWAYSONTOP";
	public static final String STRING_LABEL_TRUE = "STRING_LABEL_TRUE";
	public static final String STRING_LABEL_FALSE = "STRING_LABEL_FALSE";
	public static final String STRING_LABEL_LOCATION = "STRING_LABEL_LOCATION";
	public static final String STRING_LABEL_LOCATION_RIGHT = "STRING_LABEL_LOCATION_RIGHT";
	public static final String STRING_LABEL_LOCATION_BOTTOM = "STRING_LABEL_LOCATION_BOTTOM";
	public static final String STRING_LABEL_LOCATION_TOP = "STRING_LABEL_LOCATION_TOP";
	public static final String STRING_LABEL_LOCATION_LEFT = "STRING_LABEL_LOCATION_LEFT";
	public static final String STRING_LABEL_LANGUAGE = "STRING_LABEL_LANGUAGE";
	public static final String STRING_LABEL_NEWBROWSER = "STRING_LABEL_NEWBROWSER";
	public static final String STRING_TEXTFIELD_BROWSERNAME = "STRING_TEXTFIELD_BROWSERNAME";
	public static final String STRING_LABEL_BROWSERNAME = "STRING_LABEL_BROWSERNAME";
	public static final String STRING_LABEL_BROWSERICON = "STRING_LABEL_BROWSERICON";
	public static final String STRING_BUTTON_BROWSE = "STRING_BUTTON_BROWSE";
	public static final String STRING_BUTTON_BROWSERNEW = "STRING_BUTTON_BROWSERNEW";
	public static final String STRING_ICONEXT_DESC = "STRING_ICONEXT_DESC";
	public static final String STRING_LABEL_BROWSERVERSION = "STRING_LABEL_BROWSERVERSION";
	public static final String STRING_LABEL_BROWSEREXEC = "STRING_LABEL_BROWSEREXEC";
	public static final String STRING_BUTTON_DELETE = "STRING_BUTTON_DELETE";
	public static final String STRING_LABEL_NOBROWSERVERSIONSTRING = "STRING_LABEL_NOBROWSERVERSIONSTRING";
	public static final String STRING_LABEL_COLOR = "STRING_LABEL_COLOR";
	public static final String STRING_BUTTON_COLOR_CHANGE = "STRING_BUTTON_COLOR_CHANGE";
	public static final String STRING_BUTTON_COLOR_RESET = "STRING_BUTTON_COLOR_RESET";

	public static final String MESSAGE_VALUE_ERROR_COPY_LANGUAGE = "MESSAGE_VALUE_ERROR_COPY_LANGUAGE";
	public static final String MESSAGE_TITLE_ERROR = "MESSAGE_TITLE_ERROR";
	public static final String MESSAGE_TITLE_INFORMATION = "MESSAGE_TITLE_INFORMATION";
	public static final String MESSAGE_VALUE_ERROR_FILENOTEXISTS_LANGUAGE = "MESSAGE_VALUE_ERROR_FILENOTEXISTS_LANGUAGE";
	public static final String MESSAGE_VALUE_ERROR_NODRAGABLEFILE = "MESSAGE_VALUE_ERROR_NODRAGABLEFILE";
	public static final String MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE = "MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE";
	public static final String MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED = "MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED";
	public static final String MESSAGE_VALUE_ERROR_NOEXECUTABLE = "MESSAGE_VALUE_ERROR_NOEXECUTABLE";
	public static final String MESSAGE_VALUE_ERROR_EXECUTABLENOTHANDABLE = "MESSAGE_VALUE_ERROR_EXECUTABLENOTHANDABLE";
	public static final String MESSAGE_VALUE_ERROR_MODELLOADING = "MESSAGE_VALUE_ERROR_MODELLOADING";
	public static final String MESSAGE_VALUE_ERROR_TRYTOFALLBACK = "MESSAGE_VALUE_ERROR_TRYTOFALLBACK";
	public static final String MESSAGE_VALUE_ERROR_LOADLANGUAGE = "MESSAGE_VALUE_ERROR_LOADLANGUAGE";
	public static final String MESSAGE_VALUE_ERROR_LOADPREFERENCESFILE = "MESSAGE_VALUE_ERROR_LOADPREFERENCESFILE";
	public static final String MESSAGE_VALUE_ERROR_CREATECONFIGURATIONFILE = "MESSAGE_VALUE_ERROR_CREATECONFIGURATIONFILE";
	public static final String MESSAGE_VALUE_ERROR_TRYTOLOADDEFAULTVALUE = "MESSAGE_VALUE_ERROR_TRYTOLOADDEFAULTVALUE";
	public static final String MESSAGE_VALUE_ERROR_CREATEPREFERENCESFILE = "MESSAGE_VALUE_ERROR_CREATEPREFERENCESFILE";
	public static final String MESSAGE_VALUE_ERROR_TRYAGAIN = "MESSAGE_VALUE_ERROR_TRYAGAIN";
	public static final String MESSAGE_VALUE_ERROR_PREFERENCEFILENOTEXISTS = "MESSAGE_VALUE_ERROR_PREFERENCEFILENOTEXISTS";
	public static final String MESSAGE_VALUE_ERROR_PREFERENCENOTEXISTS = "MESSAGE_VALUE_ERROR_PREFERENCENOTEXISTS";
	public static final String MESSAGE_VALUE_ERROR_SETTINGCOLOR = "MESSAGE_VALUE_ERROR_SETTINGCOLOR";
	public static final String MESSAGE_VALUE_ERROR_FATAL = "MESSAGE_VALUE_ERROR_FATAL";
	
	public static final String STRING_TOOLTIP_DRAGDROP_SHORTCUT = "STRING_TOOLTIP_DRAGDROP_SHORTCUT";
	public static final String ANIMATION_ENABLED = "ANIMATION_ENABLED";

	/**
	 * Singleton pattern.
	 * 
	 * @return this
	 */
	public static synchronized ConfigManager getInstance() {
		if (configMng == null) {
			ConfigManager.configMng = new ConfigManager();
			return ConfigManager.configMng;
		}
		return ConfigManager.configMng;
	}

	/**
	 * Constructor to initialize the configuration and string bundle.
	 * Calls to load the preferences and the language file.
	 */
	public ConfigManager() {
		try {
			configBundle = new Properties();
			configBundle.load(Tools.fileManager.getResource(ConfigManager.CONFIG_FILE_BASENAME));
		} catch (final IOException ioe) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK));
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_CONFIGURATIONNOTLOADED + ": "+ioe.getMessage());
			this.createConfigFile();
			try {
				configBundle = new Properties();
				configBundle.load(Tools.fileManager.getResource(ConfigManager.CONFIG_FILE_BASENAME));
			} catch (final IOException ioe2) {
				Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_FATAL));
				Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_CONFIGURATIONNOTLOADED+ " (TRY 2.1) : "+ioe2.getMessage());
				System.exit(0);
			} catch (final NullPointerException npe2) {
				Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_FATAL));
				Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_NP_CONFIGURATIONNOTLOADED+ " (TRY 2.1) : "+npe2.getMessage());
				System.exit(0);
			}
		} catch (final NullPointerException npe) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK));
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_NP_CONFIGURATIONNOTLOADED + " : "+npe.getMessage());
			Tools.configMng.createConfigFile();
			try {
				configBundle = new Properties();
				configBundle.load(Tools.fileManager.getResource(ConfigManager.CONFIG_FILE_BASENAME));
			} catch (final IOException ioe3) {
				Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_FATAL));
				Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_CONFIGURATIONNOTLOADED+ " (TRY 2.2) : "+ioe3.getMessage());
				System.exit(0);
			} catch (final NullPointerException npe3) {
				Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), Tools.configMng.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + Tools.configMng.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_FATAL));
				Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_NP_CONFIGURATIONNOTLOADED+ " (TRY 2.2) : "+npe3.getMessage());
				System.exit(0);
			}
		}

		Tools.fileManager.initFolder(this.getConfiguration(ConfigManager.PREFERENCES_FOLDER));
		Tools.fileManager.initFolder(this.getConfiguration(ConfigManager.MODEL_FOLDER));
		Tools.fileManager.initFolder(this.getConfiguration(ConfigManager.STRINGS_FOLDER));
		loadPreferences();
		searchLanguages();
		strings = new Properties();
		loadLanguageFile(this.getPreference(ConfigManager.LANGUAGE));
	}

	/**
	 * Returns the file path to the configuration, preferences or model file.
	 * 
	 * @param key the key to switch between the configuration, preferences and model file
	 * @return the file path or null
	 */
	private String getFilePath(final String key) {
		if (key == ConfigManager.CONFIG_FILE) {
			return ConfigManager.DefaultConfiguration.getDefaultValue(ConfigManager.CONFIG_FILE);
		}
		if (key == ConfigManager.PREFERENCES_FILE) {
			return this.getConfiguration(ConfigManager.PREFERENCES_FOLDER) + System.getProperty("file.separator") + this.getConfiguration(ConfigManager.PREFERENCES_FILE);
		}
		if (key == ConfigManager.MODEL_FILE) {
			return this.getConfiguration(ConfigManager.MODEL_FOLDER) + System.getProperty("file.separator") + this.getConfiguration(ConfigManager.MODEL_FILE);
		}
		return null;
	}

	/**
	 * Calls to create a new configuration file.
	 */
	private void createConfigFile() {
		try {
			Tools.fileManager.newUTF8File(ConfigManager.DefaultConfiguration.getConfiguration(), this.getFilePath(ConfigManager.CONFIG_FILE));
		} catch (final IOException e) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_CREATECONFIGURATIONFILE));
			Tools.logManager.finest(this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_CREATECONFIGURATIONFILE)+ ": "+e.getMessage());
			System.exit(0);
		}
	}

	/**
	 * Returns the configuration entry for the given key.
	 * 
	 * @param key the key for the configuration entry
	 * @return the configuration entry
	 */
	public String getConfiguration(final String key) {
		try {
			return configBundle.getProperty(key) != null ? configBundle.getProperty(key) : ConfigManager.DefaultConfiguration.getDefaultValue(key);
		} catch (final MissingResourceException mre) {
			if (!Controller.getInstance().isStartingApp()) {
				Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_MR_CONFIGURATIONMISSING+ ": "+mre.getLocalizedMessage());
				final int returnValue = Tools.messageBox.question(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_YES) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOLOADDEFAULTVALUE) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_NO) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK), new String[] { this.getStringFor(ConfigManager.STRING_STANDARDS_YES), this.getStringFor(ConfigManager.STRING_STANDARDS_NO) });
				if (returnValue == Tools.messageBox.ANSWER_YES) {
					return ConfigManager.DefaultConfiguration.getDefaultValue(key);
				} else if (returnValue == Tools.messageBox.ANSWER_NO) {
					this.createConfigFile();
					return this.getConfiguration(key);
				}
			}
		} catch (final NullPointerException npe) {
			Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_NP_CONFIGURATIONNOTLOADED + " - " + npe.getMessage());
		}
		return ConfigManager.DefaultConfiguration.getDefaultValue(key);
	}

	/**
	 * Calls to create or load the preferences file.
	 */
	private void loadPreferences() {
		preferences = new Properties();
		if (!Tools.fileManager.exists(this.getFilePath(ConfigManager.PREFERENCES_FILE))) {
			try {
				Tools.fileManager.newUTF8File(ConfigManager.DefaultConfiguration.getPreferences(), this.getFilePath(ConfigManager.PREFERENCES_FILE));
			} catch (final IOException e) {
				Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_CREATEPREFERENCESFILE));
				Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_PREFERENCESNOTLOADED + " : " + e.getMessage());
				System.exit(0);
			}
		}
		try {
			preferences.load(Tools.fileManager.openUTF8File(this.getFilePath(ConfigManager.PREFERENCES_FILE)));
		} catch (final FileNotFoundException e) {
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_MR_PREFERENCESMISSING + " - " + e.getMessage());
			final int returnValue = Tools.messageBox.question(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_LOADPREFERENCESFILE) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_YES) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYAGAIN) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_NO) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK), new String[] { this.getStringFor(ConfigManager.STRING_STANDARDS_YES), this.getStringFor(ConfigManager.STRING_STANDARDS_NO) });
			if (returnValue == Tools.messageBox.ANSWER_YES) {
				this.loadPreferences();
			} else if (returnValue == Tools.messageBox.ANSWER_NO) {
				return;
			}
		} catch (final IOException e) {
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_PREFERENCESNOTLOADED + " - " + e.getMessage());
			final int returnValue = Tools.messageBox.question(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_LOADPREFERENCESFILE) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_YES) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYAGAIN) + "\n" + this.getStringFor(ConfigManager.STRING_STANDARDS_NO) + " - " + this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK), new String[] { this.getStringFor(ConfigManager.STRING_STANDARDS_YES), this.getStringFor(ConfigManager.STRING_STANDARDS_NO) });
			if (returnValue == Tools.messageBox.ANSWER_YES) {
				this.loadPreferences();
			} else if (returnValue == Tools.messageBox.ANSWER_NO) {
				return;
			}
		}
	}

	/**
	 * Sets a preference entry to the bundle.
	 * 
	 * @param key the key for the preference entry
	 * @param value the preference entry
	 */
	public void setPreference(final String key, final String value) {
		preferences.setProperty(key, value);
	}

	/**
	 * Sets all preferences in the given hash map to the bundle.
	 * 
	 * @param map the map holding the preferences
	 */
	public void setPreferences(final HashMap<String, String> map) {
		preferences.putAll(map);
	}

	/**
	 * Returns a preference for the given key.
	 * 
	 * @param key the key for the preference entry
	 * @return the preference entry
	 */
	public String getPreference(final String key) {
		try {
			return preferences.getProperty(key) != null ? preferences.getProperty(key) : ConfigManager.DefaultConfiguration.getDefaultValue(key);
		} catch (final MissingResourceException mre) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_PREFERENCEFILENOTEXISTS + "\n" + ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK));
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_MR_PREFERENCESMISSING + " - " + mre.getMessage());
		} catch (final NullPointerException e) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_PREFERENCENOTEXISTS) + "\n" + ConfigManager.MESSAGE_VALUE_ERROR_TRYTOFALLBACK);
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_NP_PREFERENCESNOTLOADED + " - " + e.getMessage());
		}
		return ConfigManager.DefaultConfiguration.getDefaultValue(key);
	}

	/**
	 * Calls to save the preferences to the preferences file.
	 */
	public void savePreferences() {
		try {
			this.savePreferences(Tools.fileManager.getOutputStream(this.getFilePath(PREFERENCES_FILE)), null);
		} catch (FileNotFoundException e) {
			Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_MR_PREFERENCESMISSING + " - " + e.getMessage());
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED));
		} catch (IOException e) {
			Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_IO_PREFERENCESNOTSAVED + " - " + e.getMessage());
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED));
		}
	}

	/**
	 * Saves the preferences to the given output stream.
	 * 
	 * @param out the output stream to write to
	 * @param comments optional comments
	 */
	public void savePreferences(final OutputStream out, final String comments) {
		try {
			preferences.store(out, comments);
		} catch (final IOException e) {
			Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_IO_PREFERENCESNOTSAVED + " - " + e.getMessage());
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), this.getStringFor(ConfigManager.MESSAGE_TITLE_ERROR), this.getStringFor(ConfigManager.MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED));
		}
	}

	/**
	 * Calls to check the existence of the language file for the given language id.
	 * 
	 * @param lng the language id
	 * @return true if the language file exists
	 */
	public boolean languageExists(final String lng) {
		return Tools.fileManager.exists(Tools.fileManager.userDir + this.getConfiguration(ConfigManager.STRINGS_FOLDER) + System.getProperty("file.separator") + lng + "." + this.getConfiguration(ConfigManager.STRINGS_FILEEXT)) || lng.equalsIgnoreCase(this.getConfiguration(ConfigManager.LANGUAGE_DEFAULT));
	}

	/**
	 * Calls to get the language file names in the language folder.
	 */
	private void searchLanguages() {
		languages = Tools.fileManager.getFileNames(this.getConfiguration(ConfigManager.STRINGS_FOLDER), "." + this.getConfiguration(ConfigManager.STRINGS_FILEEXT));
	}

	/**
	 * Calls to search for language files and calls to load the currently choosen language.
	 */
	public void updateLanguage() {
		this.searchLanguages();
		this.loadLanguageFile(this.getPreference(ConfigManager.LANGUAGE));
	}

	/**
	 * Calls to delete emmpty language files, search for language files and calls to load the default language.
	 */
	private void resetLanguages() {
		Tools.fileManager.deleteEmptyFiles(this.getConfiguration(ConfigManager.STRINGS_FOLDER), "." + this.getConfiguration(ConfigManager.STRINGS_FILEEXT));
		this.searchLanguages();
		this.loadLanguageFile(this.getConfiguration(ConfigManager.LANGUAGE_DEFAULT));
	}

	/**
	 * Loads the language file for the given language id.
	 * 
	 * @param lng
	 *            the key indicating the language
	 */
	private void loadLanguageFile(final String lng) {
		try {
			if (lng.equalsIgnoreCase(this.getConfiguration(ConfigManager.LANGUAGE_DEFAULT))) {
				strings.load(Tools.fileManager.getResource(lng + "." + this.getConfiguration(ConfigManager.STRINGS_FILEEXT)));
			} else {
				strings.load(Tools.fileManager.openUTF8File(this.getConfiguration(ConfigManager.STRINGS_FOLDER) + System.getProperty("file.separator") + lng + "." + this.getConfiguration(ConfigManager.STRINGS_FILEEXT)));
			}
		} catch (final FileNotFoundException e) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), ConfigManager.DefaultConfiguration.MESSAGE_TITLE_ERROR, ConfigManager.DefaultConfiguration.MESSAGE_VALUE_ERROR_LANGUAGEFILENOTEXISTS + "\n" + ConfigManager.DefaultConfiguration.MESSAGE_VALUE_ERROR_TRYTOFALLBACK);
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_MR_LANGUAGEMISSING + " - " + e.getMessage());
			this.resetLanguages();
			this.setPreference(ConfigManager.LANGUAGE, ConfigManager.DefaultConfiguration.getDefaultValue(ConfigManager.LANGUAGE_DEFAULT));
		} catch (final IOException e) {
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), ConfigManager.DefaultConfiguration.MESSAGE_TITLE_ERROR, ConfigManager.DefaultConfiguration.MESSAGE_VALUE_ERROR_LOADLANGUAGEFAILED);
			Tools.logManager.finest(ConfigManager.DefaultConfiguration.EXCEPTION_IO_LANGUAGENOTLOADED + " - " + e.getMessage());
		}
	}

	/**
	 * Returns a string for the given key.
	 * 
	 * @param key the key for the string entry
	 * @return the string entry
	 */
	public String getStringFor(final String key) {
		try {
			return strings.getProperty(key) != null ? strings.getProperty(key) : ConfigManager.DefaultConfiguration.getDefaultValue(key);
		} catch (final MissingResourceException mre) {
			Tools.logManager.warning(ConfigManager.DefaultConfiguration.EXCEPTION_MR_LANGUAGEMISSING + " - " + mre.getMessage());
			Tools.messageBox.error(Controller.getInstance().getWindow(Controller.APP_WINDOW_MAIN), ConfigManager.DefaultConfiguration.MESSAGE_TITLE_ERROR, ConfigManager.DefaultConfiguration.MESSAGE_VALUE_ERROR_NOLANGUAGEFILE);
			return ConfigManager.DefaultConfiguration.getDefaultValue(key);
		} 
	}

	/**
	 * Returns an iterator over the currently loaded language files.
	 * 
	 * @return the currently loaded language files
	 */
	public Iterator<String> getInstalledLanguages() {
		return languages.iterator();
	}

	/**
	 * Returns all loaded language files.
	 * 
	 * @return all currently loaded language files
	 */
	public String[] getAllLanguages() {
		String[] a = new String[languages.size()];
		final String[] l = languages.toArray(a);
		a = new String[languages.size() + 1];
		for (int i = 0; i <= languages.size() - 1; i++) {
			a[i + 1] = l[i];
		}
		a[0] = this.getConfiguration(ConfigManager.LANGUAGE_DEFAULT);
		return a;
	}

	/**
	 * Returns the local of the currently selected language.
	 * 
	 * @return the local of the currently selected language or null
	 */
	public Locale getLocale() {
		final String language = this.getPreference(ConfigManager.LANGUAGE);
		if (language.equalsIgnoreCase("english")) {
			return Locale.ENGLISH;
		}
		if (language.equalsIgnoreCase("deutsch")) {
			return Locale.GERMAN;
		}
		return Locale.ENGLISH;
	}

	/**
	 * Private static nested class managing hardcoded default configuration and
	 * preferences in case the files are not found, deleted or any error occurs.
	 */
	private static class DefaultConfiguration {
		// configurations
		public static final String CONFIG_FILE = "config.properties";
		public static final String PREFERENCES_FOLDER = "prefs";
		public static final String PREFERENCES_FILE = "browserchooser.pref";
		@SuppressWarnings("unused")
		public static final String MODEL_FOLDER = "model";
		public static final String MODEL_FILE = "browser.ser";
		public static final String STRINGS_FOLDER = "strings";
		public static final String STRINGS_FILEEXT = "lng";
		@SuppressWarnings("unused")
		public static final String LANGUAGE_DEFAULT = "english";

		public static final String DOCKLET_LOCATION_TOP = "top";
		public static final String DOCKLET_LOCATION_RIGHT = "right";
		public static final String DOCKLET_LOCATION_BOTTOM = "bottom";
		public static final String DOCKLET_LOCATION_LEFT = "left";
		public static final String DOCKLET_ICON_SIZE_MAX = "128";
		public static final String DOCKLET_ICON_SIZE_MIN = "16";
		public static final String DOCKLET_ICON_SIZE_EXTENT = "8";
		public static final String DOCKLET_ICON_SPACE = "8";

		public static final String SETTINGS_SIZE_WIDTH = "400";
		public static final String SETTINGS_SIZE_HEIGHT = "280";
		public static final String SETTINGS_BUTTONPANEL_SIZE_WIDTH = "400";
		public static final String SETTINGS_BUTTONPANEL_SIZE_HEIGHT = "40";
		public static final String SETTINGS_BUTTON_SAVE_COORDINATE_X = "5";
		public static final String SETTINGS_BUTTON_SAVE_COORDINATE_Y = "5";
		public static final String SETTINGS_BUTTON_SAVE_SIZE_WIDTH = "90";
		public static final String SETTINGS_BUTTON_SAVE_SIZE_HEIGHT = "25";
		public static final String SETTINGS_BUTTON_ABORT_COORDINATE_X = "100";
		public static final String SETTINGS_BUTTON_ABORT_COORDINATE_Y = "5";
		public static final String SETTINGS_BUTTON_ABORT_SIZE_WIDTH = "90";
		public static final String SETTINGS_BUTTON_ABORT_SIZE_HEIGHT = "25";

		// preferences
		public static final String DOCKLET_SIZE_WIDTH = "40";
		public static final String DOCKLET_SIZE_HEIGHT = "40";
		public static final String DOCKLET_ALWAYSONTOP = "true";
		@SuppressWarnings("unused")
		public static final String DOCKLET_LOCATION = "top";
		public static final String DOCKLET_ICON_SIZE = "32";
		public static final String DOCKLET_BACKGROUND = "0xFF0000";
		public static final String LANGUAGE = "english";
		public static final String ANIMATION_ENABLED = "false";
		public static final String ANIMATION_SPEED = "1";
		public static final String ANIMATION_DELAY = "200";

		// hardcoded strings, messages, exceptions
		public static final String MESSAGE_VALUE_ERROR_NOLANGUAGEFILE = "Sorry, there is no language file for the choosen language. Please download a new version";
		public static final String MESSAGE_VALUE_ERROR_LOADLANGUAGEFAILED = "Sorry, but an error occured while loading the language file!";
		public static final String MESSAGE_VALUE_ERROR_LANGUAGEFILENOTEXISTS = "Sorry, but the language file does not exists!";

		public static final String MESSAGE_TITLE_ERROR = "Error";
		@SuppressWarnings("unused")
		public static final String MESSAGE_TITLE_INFORMATION = "Information";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_REFERENCESNOTSAVED = "Preferences could not be saved!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_COPY_LANGUAGE = "Language file could not be copied!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_LOADLANGUAGE = "Language file could not be loaded! Please make sure you have access and try again!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_LOADPREFERENCESFILE = "Preferences file could not be loaded! Please make sure you have access and try again!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_FILENOTEXISTS_LANGUAGE = "Language file does not exist! Maybe it was removed somehow.";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_NOCONFIGURATIONFILE = "Configuration file not found!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_CREATECONFIGURATIONFILE = "Configuration file could not be created! Please make sure you have access and try again!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_CREATEPREFERENCESFILE = "Preferences file could not be created! Please make sure you have access and try again!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_PREFERENCEFILENOTEXISTS = "Preferences file may not exist!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_PREFERENCENOTEXISTS = "This preferences property does not exist!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_NODRAGABLEFILE = "This is not a file and can not be dropped.";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_NOEXECUTABLE = "There is no executable for this application. Please check your settings!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_EXECUTABLENOTHANDABLE = "The executable you declared could not be handled. Please check your settings!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_MODELLOADING = "The setting information of your application(s) could not be loaded! Please try again!";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_TRYTOLOADDEFAULTVALUE = "Try to load default value?";
		public static final String MESSAGE_VALUE_ERROR_TRYTOFALLBACK = "Try to fall back to base configuration.";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_SETTINGCOLOR = "Background color could not be set. Fall back to default color.";
		@SuppressWarnings("unused")
		public static final String MESSAGE_VALUE_ERROR_FATAL = "A fatal error occured. The application will close now. You can restart the application now. If this does not help, please contact the developer team.";

		
		public static final String EXCEPTION_IO_LANGUAGENOTLOADED = "Exception - IO - loading language failed";
		public static final String EXCEPTION_MR_LANGUAGEMISSING = "Exception - MR - resource language file does not exist";
		public static final String EXCEPTION_MR_CONFIGURATIONMISSING = "Exception - MR - resource configuration file does not exist";
		public static final String EXCEPTION_NP_CONFIGURATIONNOTLOADED = "Exception - NP - loading configuration file failed";
		public static final String EXCEPTION_IO_CONFIGURATIONNOTLOADED = "Exception - IO - loading configuration file failed";
		public static final String EXCEPTION_MR_PREFERENCESMISSING = "Exception - MR - resource preferences file does not exist";
		public static final String EXCEPTION_NP_PREFERENCESNOTLOADED = "Exception - NP - loading preferences file failed";
		public static final String EXCEPTION_IO_PREFERENCESNOTSAVED = "Exception - IO - saving preferences failed";
		public static final String EXCEPTION_IO_PREFERENCESNOTLOADED = "Exception - IO - loading preferences failed";
		/**
		 * Returns new default preferences.
		 * 
		 * @return default preferences
		 */
		public static StringBuffer getPreferences() {
			final StringBuffer sb = new StringBuffer();
			sb.append(ConfigManager.DOCKLET_SIZE_WIDTH + "=" + DefaultConfiguration.DOCKLET_SIZE_WIDTH + "\n");
			sb.append(ConfigManager.DOCKLET_SIZE_HEIGHT + "=" + DefaultConfiguration.DOCKLET_SIZE_HEIGHT + "\n");
			sb.append(ConfigManager.DOCKLET_LOCATION + "=" + ConfigManager.DOCKLET_LOCATION_TOP + "\n");
			sb.append(ConfigManager.DOCKLET_ALWAYSONTOP + "=" + DefaultConfiguration.DOCKLET_ALWAYSONTOP + "\n");
			sb.append(ConfigManager.DOCKLET_ICON_SIZE + "=" + DefaultConfiguration.DOCKLET_ICON_SIZE + "\n");
			sb.append(ConfigManager.DOCKLET_BACKGROUND + "=" + DefaultConfiguration.DOCKLET_BACKGROUND + "\n");
			sb.append(ConfigManager.LANGUAGE + "=" + DefaultConfiguration.LANGUAGE + "\n");
			sb.append(ConfigManager.ANIMATION_ENABLED + "=" + DefaultConfiguration.ANIMATION_ENABLED + "\n");
			sb.append(ConfigManager.ANIMATION_SPEED + "=" + DefaultConfiguration.ANIMATION_SPEED + "\n");
			sb.append(ConfigManager.ANIMATION_DELAY + "=" + DefaultConfiguration.ANIMATION_DELAY + "\n");
			return sb;
		}

		/**
		 * Returns new default configuration.
		 * 
		 * @return default configuration
		 */
		public static StringBuffer getConfiguration() {
			final StringBuffer sb = new StringBuffer();
			sb.append(ConfigManager.CONFIG_FILE + "=" + DefaultConfiguration.CONFIG_FILE + "\n");
			sb.append(ConfigManager.MODEL_FILE + "=" + DefaultConfiguration.MODEL_FILE + "\n");
			sb.append(ConfigManager.STRINGS_FOLDER + "=" + DefaultConfiguration.STRINGS_FOLDER + "\n");
			sb.append(ConfigManager.STRINGS_FILEEXT + "=" + DefaultConfiguration.STRINGS_FILEEXT + "\n");
			sb.append(ConfigManager.PREFERENCES_FOLDER + "=" + DefaultConfiguration.PREFERENCES_FOLDER + "\n");
			sb.append(ConfigManager.PREFERENCES_FILE + "=" + DefaultConfiguration.PREFERENCES_FILE + "\n");
			sb.append(ConfigManager.DOCKLET_LOCATION_TOP + "=" + DefaultConfiguration.DOCKLET_LOCATION_TOP + "\n");
			sb.append(ConfigManager.DOCKLET_LOCATION_RIGHT + "=" + DefaultConfiguration.DOCKLET_LOCATION_RIGHT + "\n");
			sb.append(ConfigManager.DOCKLET_LOCATION_BOTTOM + "=" + DefaultConfiguration.DOCKLET_LOCATION_BOTTOM + "\n");
			sb.append(ConfigManager.DOCKLET_LOCATION_LEFT + "=" + DefaultConfiguration.DOCKLET_LOCATION_LEFT + "\n");
			sb.append(ConfigManager.DOCKLET_ICON_SIZE_MAX + "=" + DefaultConfiguration.DOCKLET_ICON_SIZE_MAX + "\n");
			sb.append(ConfigManager.DOCKLET_ICON_SIZE_MIN + "=" + DefaultConfiguration.DOCKLET_ICON_SIZE_MIN + "\n");
			sb.append(ConfigManager.DOCKLET_ICON_SIZE_EXTENT + "=" + DefaultConfiguration.DOCKLET_ICON_SIZE_EXTENT + "\n");
			sb.append(ConfigManager.DOCKLET_ICON_SPACE + "=" + DefaultConfiguration.DOCKLET_ICON_SPACE + "\n");
			sb.append(ConfigManager.SETTINGS_SIZE_WIDTH + "=" + DefaultConfiguration.SETTINGS_SIZE_WIDTH + "\n");
			sb.append(ConfigManager.SETTINGS_SIZE_HEIGHT + "=" + DefaultConfiguration.SETTINGS_SIZE_HEIGHT + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTONPANEL_SIZE_WIDTH + "=" + DefaultConfiguration.SETTINGS_BUTTONPANEL_SIZE_WIDTH + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTONPANEL_SIZE_HEIGHT + "=" + DefaultConfiguration.SETTINGS_BUTTONPANEL_SIZE_HEIGHT + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_SAVE_COORDINATE_X + "=" + DefaultConfiguration.SETTINGS_BUTTON_SAVE_COORDINATE_X + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_SAVE_COORDINATE_Y + "=" + DefaultConfiguration.SETTINGS_BUTTON_SAVE_COORDINATE_Y + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_SAVE_SIZE_WIDTH + "=" + DefaultConfiguration.SETTINGS_BUTTON_SAVE_SIZE_WIDTH + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_SAVE_SIZE_HEIGHT + "=" + DefaultConfiguration.SETTINGS_BUTTON_SAVE_SIZE_HEIGHT + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_ABORT_COORDINATE_X + "=" + DefaultConfiguration.SETTINGS_BUTTON_ABORT_COORDINATE_X + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_ABORT_COORDINATE_Y + "=" + DefaultConfiguration.SETTINGS_BUTTON_ABORT_COORDINATE_Y + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_ABORT_SIZE_WIDTH + "=" + DefaultConfiguration.SETTINGS_BUTTON_ABORT_SIZE_WIDTH + "\n");
			sb.append(ConfigManager.SETTINGS_BUTTON_ABORT_SIZE_HEIGHT + "=" + DefaultConfiguration.SETTINGS_BUTTON_ABORT_SIZE_HEIGHT + "\n");
			return sb;
		}

		/**
		 * Returns the default value for the given configuration key.
		 * 
		 * @param key the key for the configuration entry
		 * @return the default configuration value or null
		 */
		public static String getDefaultValue(final String key) {
			try {
				return (String) DefaultConfiguration.class.getField(key).get(null);
			} catch (final IllegalArgumentException e) {
				Tools.logManager.warning("DefaultConfiguration::getDefaultValue() - " + e.getMessage());
			} catch (final SecurityException e) {
				Tools.logManager.warning("DefaultConfiguration::getDefaultValue() - " + e.getMessage());
			} catch (final IllegalAccessException e) {
				Tools.logManager.warning("DefaultConfiguration::getDefaultValue() - " + e.getMessage());
			} catch (final NoSuchFieldException e) {
				Tools.logManager.warning("DefaultConfiguration::getDefaultValue() - " + e.getMessage());
			}
			return null;
		}
	}
}